import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () => import("../views/Home.vue")
const Login = () => import("../views/Login.vue")
const Main = () => import("../views/Main.vue")

const UserEdit = () => import("../views/Sublist/UserEdit.vue")
const UserList = () => import("../views/Sublist/UserList.vue")

const TaskEdit = () => import("../views/Sublist/TaskEdit.vue")
const TaskList = () => import("../views/Sublist/TaskList.vue")

const CateEdit = () => import("../views/Sublist/CateEdit.vue")
const CateList = () => import("../views/Sublist/CateList.vue")
const CateExport = () => import("../views/Sublist/CateExport.vue")

const AuditList = () => import("../views/Sublist/AuditList.vue")
const AuditConfirm = () => import("../views/Sublist/AuditConfirm.vue")
const AuditHistory = () => import("../views/Sublist/AuditHistory.vue")

const JournalList = () => import("../views/Sublist/JournalList.vue")
const NoticeList = () => import("../views/Sublist/NoticeList.vue")






Vue.use(VueRouter)

const routes = [
  { path:'/login',name:'login',component:Login,meta:{ isPublic:true } },
  {
    path: '/',
    // name:'Main',
    component: Main,
    children: [
      {
        path:'/',           
        redirect:'/home'    
      },
      { path:'/home',name:'home',component:Home },
      { path:'/createUser',component:UserEdit },
      { path:'/userList',component:UserList },
      { path:'/createUser/:id',component:UserEdit,props:true },

      { path:'/createTask',component:TaskEdit },
      { path:'/taskList',component:TaskList },
      { path:'/createTask/:id',component:TaskEdit,props:true },
      { path:'/taskAdd/:parentId',component:TaskEdit,props:true },

      { path:'/createCate',component:CateEdit },
      { path:'/cateList',component:CateList },
      { path:'/createCate/:id',component:CateEdit,props:true },


      { path:'/auditList',component:AuditList },
      { path:'/auditConfirm/:id',component:AuditConfirm,props:true },
      { path:'/auditHistory',component:AuditHistory,props:true },

      { path:'/journalList',component:JournalList,props:true },
      
      { path:'/CateExport',component:CateExport,props:true },

      { path:'/noticeList',component:NoticeList,props:true }


    ]
  }
]

const router = new VueRouter({
  routes
})

//路由拦截
router.beforeEach((to, from, next) => {
  if (!to.meta.isPublic && !localStorage.token) {
    return next('/login')
  }
  next()
})

export default router